package seven_ThreadPool;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
//        method_1();
        method_2();
    }

    private static void method_2() {
        try{
            Socket s = new Socket("127.0.0.1", 9999);
            PrintStream ps = new PrintStream(s.getOutputStream());
            Scanner sc = new Scanner(System.in);
            while (true) {
                System.out.print("Please input: ");
                String str = sc.nextLine();
                ps.println(str);
                ps.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void method_1() {
        //         看视频说是阻塞了，我自己试过就是没close()
        PrintStream ps = null;
        try{
            Socket s = new Socket("192.168.43.125", 9999);
            ps = new PrintStream(s.getOutputStream());
            ps.print("hello Server");
            ps.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            ps.close();
        }
    }
}
